package avicit.bdp.dms.tdm.rest;

import avicit.bdp.dms.tdm.dto.BdpAssetMountFileDTO;
import avicit.bdp.dms.tdm.service.BdpAssetMountFileService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "资产挂载文件")
@RequestMapping("/api/bdp/dms/asset/mount/file")
public class BdpAssetMountFileRest {

  @Resource private BdpAssetMountFileService bdpAssetMountFileService;

  @ApiOperation(value = "新增")
  @PostMapping
  public ResponseMsg<String> save(@RequestBody BdpAssetMountFileDTO dto) {
    ResponseMsg<String> responseMsg = new ResponseMsg<>();
    bdpAssetMountFileService.save(dto);
    responseMsg.setResponseBody(dto.getId());
    return responseMsg;
  }

  @ApiOperation(value = "修改")
  @PutMapping("/update")
  public ResponseMsg<Boolean> update(@RequestBody BdpAssetMountFileDTO dto) {
    ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
    bdpAssetMountFileService.update(dto);
    responseMsg.setResponseBody(bdpAssetMountFileService.update(dto) > 0);
    return responseMsg;
  }

  @ApiOperation(value = "通过ID查询")
  @ApiParam(value = "id", name = "id", required = true)
  @GetMapping("/{id}")
  public ResponseMsg<BdpAssetMountFileDTO> queryById(@PathVariable String id) {
    ResponseMsg<BdpAssetMountFileDTO> responseMsg = new ResponseMsg<>();
    responseMsg.setResponseBody(bdpAssetMountFileService.queryById(id));
    return responseMsg;
  }

  @ApiOperation(value = "通过资产ID查询")
  @ApiParam(value = "assetId", name = "assetId", required = true)
  @GetMapping("/queryByAssetId")
  public ResponseMsg<BdpAssetMountFileDTO> queryByAssetId(@RequestParam String assetId) {
    ResponseMsg<BdpAssetMountFileDTO> responseMsg = new ResponseMsg<>();
    responseMsg.setResponseBody(bdpAssetMountFileService.queryByAssetId(assetId));
    return responseMsg;
  }
}
